package com.integral.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.integral.biz.IUserInfoBiz;
import com.integral.entity.UserInfo;
import com.integral.vo.UserInfoVo;

@Controller
@RequestMapping("/userInfo")
public class UserInfoController {
	
	@Resource
	private IUserInfoBiz userInfoBiz;

	/**
	 * 查询系统用户
	 * @param request
	 * @param response
	 * @param userVo
	 * @return
	 */
	@RequestMapping(value="/findUserInfo")
	@ResponseBody
	public Map<String,Object> findUserInfo(HttpServletRequest request, HttpServletResponse response,UserInfoVo userInfoVo){
		List<UserInfo> list = userInfoBiz.findUserInfo(userInfoVo);
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("total", userInfoBiz.findUserInfoCount(userInfoVo));
		map.put("rows", list);
		return map;
	}
	/**
	 * 新增系统用户
	 * @param userInfo
	 * @return
	 */
	@RequestMapping(value="/addUserInfo")
	@ResponseBody
	public String addUserInfo(UserInfo userInfo){
		//查询用户帐号是否存在
		UserInfo user = userInfoBiz.findUserInfoByCode(userInfo);
		if(null != user){
			return "用户帐号存在！";
		}
		int i = userInfoBiz.addUserInfo(userInfo);
		if(i > 0){
			return "新增成功！";
		}else{
			return "新增失败！";
		}
		
	}
	/**
	 * 修改系统用户
	 * @param userInfo
	 * @return
	 */
	@RequestMapping(value="/updateUserInfo")
	@ResponseBody
	public String updateUserInfo(UserInfo userInfo){
		int i = userInfoBiz.updateUserInfo(userInfo);
		if(i > 0){
			return "修改成功！";
		}else{
			return "修改失败！";
		}
	}
	/**
	 * 删除系统用户
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/delUserInfo")
	@ResponseBody
	public String delUserInfo(Integer id){
		UserInfo userInfo = new UserInfo();
		userInfo.setId(id);
		int i = userInfoBiz.delUserInfo(userInfo);
		if(i > 0){
			return "删除成功！";
		}else{
			return "删除失败！";
		}
	}
}
